#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
from base.Sequence import Sequence
from base.InstructionMap import InstructionMap
from DV.gpgpu.trees.instruction_tree import *


class MainSequence(Sequence):
    """Generate a sequence of instructions that are randomly selected from the
    specified subset of CALM instructions.
    1 specify the number of instructions to be generated by setting
        instruction_count
    2 specify a the desired subset by setting the instruction_group.  Some of
        the predefined instruction subsets are listed below with the
        statement for all but one commented out. Just uncomment the subset you
        wish to use, while commenting out the others.  For more details on
        the specific instructions in each subset and a list of the other
        available predefined subsets, see
        force/py/DV/gpgpu/trees/instruction_tree.py.
    3 if you want to a specific instruction, set the_instruction2 to the
        appropriate string and use the_instruction2 in the genInstruction call.
    """

    def generate(self, **kargs):

        # 1 - set the number of instructions to generate,
        # can configure via control file with generator option -
        # 'instruction_count'
        (count_opt, count_opt_valid) = self.getOption("instruction_count")
        if count_opt_valid:
            instruction_count = count_opt
        else:
            instruction_count = 100

        # 2 - Choose the subset of GPGPU instruction you wish to use
        instruction_group = (
            RV32_G_instructions
            if self.getGlobalState("AppRegisterWidth") == 32
            else RV_G_instructions
        )

        """
        # instruction_group = BranchJump_instructions
        # instruction_group = LDST_All_instructions
        # instruction_group = ALU_Int_All_instructions
        # instruction_group = ALU_Float_All_instructions
        # instruction_group = RV32I_instructions
        # instruction_group = RV_A_instructions

        # 3 - If you want to specify a specific instruction, set
        # the_instruction2 to the appropriate string here and replace the
        # argument in the genInstruction call to the_instruction2.  For the
        # string values to use for a given instruction, search for that
        # instruction in force/py/DV/gpgpu/trees/instruction_tree.py.
        # the_instruction2 = "ADD##CALM"
        """
        for _ in range(instruction_count):
            # select a specific instruction from the instruction group
            the_instruction = self.pickWeighted(instruction_group)

            # create the instruction
            record_id = self.genInstruction(the_instruction)


#  Points to the MainSequence defined in this file
MainSequenceClass = MainSequence

#  Using GenThreadGPGPU by default, can be overriden with extended classes
GenThreadClass = GenThreadGPGPU

#  Using EnvGPGPU by default, can be overriden with extended classes
EnvClass = EnvGPGPU
